﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shop.Model;
using Shop.Framework.Runtime;
using System.Web;
using System.Web.Caching;

namespace Shop.Framework.Services {
    public class ShopService:BaseService {

        public ShopDetail GetShopDetail (){
            try {
                ShopDatabaseDataContext context = Context;
                var res = context.ShopDetails.FirstOrDefault();
                return res;
            } catch (Exception ex) {
                throw new Exception("Shop detail error occured.", ex);
            }                            
        }

        public bool LogIn(string user, string pass) {
            try {
                ShopDatabaseDataContext context = Context;
                var res = context.ShopDetails.FirstOrDefault(x => x.Login == user && x.Password == pass);
                if (res != null) {
                    HttpRuntime.Cache.Add(CMSRuntime.ShopKeeper,
                    res,
                    null,
                    DateTime.Now.AddHours(2),
                    Cache.NoSlidingExpiration,
                    CacheItemPriority.Normal,
                    null);
                }
                return res == null;
            } catch (Exception ex) {
                throw new Exception("Shop detail error occured.", ex);
            }
        }



    }
}
